//
//  AFNData.m
//  ShanProject
//
//  Created by dllo on 15/9/29.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//

#import "AFNData.h"
#import "AFNetworking.h"
@implementation AFNData


+(void)getAFNDataWithUrl:(NSString *)str  success:(void (^)(id responseObject))success
                 failure:(void (^)(NSError *error))failure
{
    
    
    
  UIActivityIndicatorView   *activityIndicator = [[UIActivityIndicatorView alloc] init];
    UIWindow *windows =   [UIApplication sharedApplication].keyWindow;
  
    
    activityIndicator.center = windows.center;
    activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

    [windows addSubview:activityIndicator];
    
    [windows bringSubviewToFront:activityIndicator];
    
    [activityIndicator startAnimating];
    
    
    UIApplication *application = [UIApplication sharedApplication];
    application.networkActivityIndicatorVisible = YES;

    
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    
    NSString *url_string = str;
    
    
    AFHTTPSessionManager * manager = [AFHTTPSessionManager manager];
    
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    [manager GET:url_string parameters:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
         success(responseObject);
        
         application.networkActivityIndicatorVisible = NO;
        [activityIndicator stopAnimating];
        
        
    } failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
         application.networkActivityIndicatorVisible = NO;
                 [activityIndicator stopAnimating];
        
        
         failure(error);
        
    }];
    
}
@end
